package cn.com.generaldata.os.paging;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

public class Filter implements Cloneable {

	private List<FilterRule> rules;
	private String sortBy;
	private byte order;

	public Filter() {
		rules = new ArrayList<FilterRule>();
		order = 0;
		sortBy = null;
	}

	public Filter(List<FilterRule> collection) {
		rules = collection;
		order = 0;
		sortBy = null;
	}

	public void addRule(FilterRule filterrule) {
		rules.add(filterrule);
	}

	public byte getOrder() {
		return order;
	}

	public void setOrder(byte byte0) {
		order = byte0;
	}

	public Collection<FilterRule> getRules() {
		return rules;
	}

	public void setRules(List<FilterRule> collection) {
		rules = collection;
	}

	public String getSortBy() {
		return sortBy;
	}

	public void setSortBy(String s) {
		sortBy = s;
	}

	@Override
	public Object clone() {
		Filter filter = new Filter();
		filter.setSortBy(getSortBy());
		filter.setOrder(getOrder());
		List<FilterRule> vector = new ArrayList<FilterRule>();
		if (getRules() != null) {
			FilterRule filterrule;
			for (Iterator<FilterRule> iterator = getRules().iterator(); iterator.hasNext(); vector.add(filterrule)) {
				filterrule = new FilterRule();
				FilterRule filterrule1 = iterator.next();
				filterrule.setFieldName(filterrule1.getFieldName());
				filterrule.setSearchType(filterrule1.getSearchType());
				filterrule.setValueType(filterrule1.getValueType());
				filterrule.setValue(filterrule1.getValue());
			}

		}
		filter.setRules(vector);
		return filter;
	}

}
